﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using haptic.src.engine;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using haptic.src.engine.animation;
using haptic.src.engine.render;
using haptic.src.engine.core;

namespace haptic.src.components
{
    [Serializable]
    public class cAppearance : Component
    {
        public cAppearance(){}
        public cAppearance(Entity oOwner) : base(oOwner) {}

        public override Result Load(haptic.src.engine.Scene oGame, ContentManager oContent)
        {
            if (m_sTexturePath != null)
            {
                m_oSprite = new Sprite(m_sTexturePath);
                m_oSprite.m_uiFrameCount = 1;
            }
            if (m_oSprite != null)
            {
                m_oSprite.Load(oContent);
                m_oSpriteInstance = new SpriteInstance(m_oSprite);
                m_oEntity.m_vSize.X = m_oSprite.m_uiFrameWidth;
                m_oEntity.m_vSize.Y = m_oSprite.m_uiFrameHeight;
                m_oSpriteInstance.Play();
            }
            return Result.Success;
        }

        public override void Update(GameTime oTime)
        {
            if (m_oSpriteInstance != null)
                m_oSpriteInstance.Update(oTime);
            base.Update(oTime);
        }

        public override void Draw(Renderer oRenderer, GameTime oTime)
        {
            if (m_oSpriteInstance != null)
                m_oSpriteInstance.Draw(oRenderer, m_oEntity.m_vPosition - m_oEntity.m_vSize * .5f);
        }

        public string m_sTexturePath;
        public Sprite m_oSprite;
        private SpriteInstance m_oSpriteInstance;
    }
}
